package com.liuym.login.common;

import com.liuym.common.exception.LoginException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author LiuYiMing
 * @date 2018/11/30 10:53
 * @describe：异常处理
 */
public class LogAndExceptionCommon {

    private static final Logger logger = LoggerFactory.getLogger(LogAndExceptionCommon.class);

    public static void recordLogAndThrowExceptionByWarn(int code, String msg, Object msgParam)
            throws LoginException {
        LoginException loginException = null;
        if (StringUtils.isEmpty(msgParam.toString())) {
            loginException = new LoginException(code, msg);
        } else {
            loginException = new LoginException(code, String.format(msg, msgParam));
        }
        logger.warn(loginException.toString());
        throw loginException;
        // return new GradeResponse<StudentException>(code, msg);

    }

    public static void recordLogAndThrowExceptionByError(int code, String msg, Object msgParam)
            throws LoginException {
        LoginException loginException = null;
        if (StringUtils.isEmpty(msgParam.toString())) {
            loginException = new LoginException(code, msg);
        } else {
            loginException = new LoginException(code, String.format(msg, msgParam));
        }
        logger.error(loginException.toString());
        throw loginException;
        // return new GradeResponse<StudentException>(code, msg);
    }
}
